<!--suppress HtmlDeprecatedAttribute -->
<script setup lang="ts">
import { openExternal } from "@/framework/util/shell";
import { hc } from "@/framework/vue/util/render";
import { CheckOutlined, DeleteOutlined, PlusOutlined } from "@ant-design/icons-vue";
import PendingButton from "@/components/framework/pending-button.vue";
import { computed, onMounted, ref } from "vue";
import { useMvndStore } from "@/pages/tools/java/mvnd-store";
import MvndInstallModal from "@/pages/tools/java/mvnd-install-modal.vue";

const mvndStore = useMvndStore();
const installModalOpen = ref(false);
const dataSource = computed(() => mvndStore.versionList);

onMounted(() => mvndStore.scanInstalledMvnd());

const uninstall = (record: any) => {
  // TODO
};

const setDefault = async (record: any) => {};
</script>

<template>
  <div class="full-view overflow-auto ph-16">
    <div class="mb-16 flex">
      <a-button type="primary" :icon="hc(PlusOutlined)" @click="installModalOpen = true">安装</a-button>
    </div>
    <a-table size="small" bordered :data-source="dataSource" :pagination="{ pageSize: 15, hideOnSinglePage: true, size: 'middle' }">
      <a-table-column title="版本名称" data-index="version" width="160px" align="center">
        <template v-slot="{ text }">
          <b>{{ text }}</b>
        </template>
      </a-table-column>
      <a-table-column title="系统默认" width="100px" align="center">
        <template v-slot="{ record }">
          <CheckOutlined v-if="false" class="color-success" />
        </template>
      </a-table-column>
      <a-table-column title="安装路径" data-index="installPath">
        <template v-slot="{ text }">
          <a-button type="link" @click="openExternal(text)">{{ text }}</a-button>
        </template>
      </a-table-column>
      <a-table-column title="操作" width="300px">
        <template v-slot="{ record }">
          <a-space>
            <a-button type="text" size="small" danger :icon="hc(DeleteOutlined)" @click="uninstall(record)">卸载</a-button>
            <pending-button type="text" size="small" v-if="true" :fn="setDefault" :fn-args="record">设为默认</pending-button>
          </a-space>
        </template>
      </a-table-column>
    </a-table>

    <mvnd-install-modal v-model:open="installModalOpen" />
  </div>
</template>
